package com.test.mchelepesa.util_rice.http_rice;

import androidx.annotation.NonNull;

import java.io.IOException;
import java.net.SocketTimeoutException;

import okhttp3.Call;
import okhttp3.EventListener;

public class TimeoutEventListener extends EventListener {

    private final Runnable onTimeoutRunnable;

    public TimeoutEventListener(Runnable onTimeoutRunnable){
        this.onTimeoutRunnable = onTimeoutRunnable;
    }

    @Override
    public void callFailed(@NonNull Call call, @NonNull IOException ioe) {
        if (ioe instanceof SocketTimeoutException && onTimeoutRunnable!=null) onTimeoutRunnable.run();
        super.callFailed(call, ioe);
    }

}
